####################################################
#
#  This file produces Figure SI-1: response curves 
#  and MP ideal points
#
####################################################


setwd("...")

load("idlBillAug48.RData")

win.metafile("responseCurves.emf", width = 8, height = 6)

plot(-idlAug48$xbar, 
     rep(1, length(idlAug48$xbar)),
     type = "n", 
     ylim = c(0, 1),
     xlab = "MP position",
     ylab = "Predicted response: Pr(Yes) per bill"
     )

xvals = seq(min(-idlAug48$xbar), 
            max(-idlAug48$xbar), 
            length.out = 100
            )

# For plotting the response curves, the polarity of the 
# ideal points is reversed, as they were estimated in the 
# "wrong" order (from right to left).

apply((1 + exp(-(t(idlAug48$betabar %*% t(cbind(-xvals, 1)))))) ^ (-1), 
      2, 
      function(x) lines(xvals, x)
      )

rug(-idlAug48$xbar)

dev.off()
